<?php
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private',false);
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="data.csv"' );
header('Content-Transfer-Encoding: binary');

$fh = fopen("php://output", 'w');
$ln = array();
foreach($this->meta['headers'] as $col)
    $ln[] = $col[2];
fputcsv($fh, $ln);
foreach($this->data as $row) {
    $ln = array();
    foreach ( $this->meta['headers'] as $col )
        $ln[] = $row[$col[0]];
    fputcsv($fh, $ln);
}
fclose($fh);
exit;
?>